import 'dart:math';

import 'package:flutter/material.dart';

enum SymmetricalMode {
  never,
  all,
  portrait,
  landscape,
}

class SafeAreaPageWrapper extends StatelessWidget {
  final Widget? child;
  final Decoration? decoration;
  final EdgeInsets? padding;
  final SymmetricalMode? symmetricalMode;

  const SafeAreaPageWrapper(
      {super.key,
      this.child,
      this.decoration,
      this.padding = EdgeInsets.zero,
      this.symmetricalMode = SymmetricalMode.landscape});

  @override
  Widget build(BuildContext context) {
    MediaQueryData metaQueryData = MediaQuery.of(context);
    final EdgeInsets safeAreasPadding = metaQueryData.padding;
    Orientation orientation = metaQueryData.orientation;
    final EdgeInsets? finalPadding;
    if (symmetricalMode == SymmetricalMode.all ||
        (symmetricalMode == SymmetricalMode.portrait &&
            orientation == Orientation.portrait) ||
        (symmetricalMode == SymmetricalMode.landscape &&
            orientation == Orientation.landscape)) {
      finalPadding = EdgeInsets.fromLTRB(
          max(safeAreasPadding.left, safeAreasPadding.right) + padding!.left,
          max(safeAreasPadding.top, safeAreasPadding.bottom) + padding!.top,
          max(safeAreasPadding.left, safeAreasPadding.right) + padding!.right,
          max(safeAreasPadding.top, safeAreasPadding.bottom) + padding!.bottom);
    } else {
      finalPadding = EdgeInsets.fromLTRB(
          safeAreasPadding.left + padding!.left,
          safeAreasPadding.top + padding!.top,
          safeAreasPadding.right + padding!.right,
          safeAreasPadding.bottom + padding!.bottom);
    }
    return Scaffold(
        body: Container(
      decoration: decoration,
      padding: finalPadding,
      child: child,
    ));
  }
}
